home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gawk / gawk213s.zoo / gawk-src-2.13 / awk.h < prev    next >
C/C++ Source or Header  |  1991-07-21  |  22KB  |  783 lines

  1. /*
  2.  * awk.h -- Definitions for gawk. 
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc.
  7.  * 
  8.  * This file is part of GAWK, the GNU implementation of the
  9.  * AWK Progamming Language.
  10.  * 
  11.  * GAWK is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 1, or (at your option)
  14.  * any later version.
  15.  * 
  16.  * GAWK is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GAWK; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26. /* ------------------------------ Includes ------------------------------ */
  27. #include <stdio.h>
  28. #include <ctype.h>
  29. #include <setjmp.h>
  30. #include <varargs.h>
  31. #include <time.h>
  32. #include <errno.h>
  33. #include <signal.h>
  34.  
  35. /* ----------------- System dependencies (with more includes) -----------*/
  36.  
  37. #ifndef VAXC
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40. #else    /* VMS w/ Digital's "VAX C" compiler */
  41. #include <types.h>
  42. #include <stat.h>
  43. #include <file.h>    /* avoid <fcntl.h> in io.c */
  44. #endif    /*VAXC*/
  45.  
  46. #include "config.h"
  47.  
  48. #ifdef __STDC__
  49. #define    P(s)    s
  50. #define MALLOC_ARG_T size_t
  51. #else
  52. #define    P(s)    ()
  53. #define MALLOC_ARG_T unsigned
  54. #define volatile
  55. #define const
  56. #endif
  57.  
  58. #ifndef SIGTYPE
  59. #define SIGTYPE    void
  60. #endif
  61.  
  62. #ifdef SIZE_T_MISSING
  63. typedef unsigned int size_t;
  64. #endif
  65.  
  66. #ifndef SZTC
  67. #define SZTC
  68. #define INTC
  69. #endif
  70.  
  71. #ifdef STDC_HEADERS
  72. #include <stdlib.h>
  73. #include <string.h>
  74. #ifdef NeXT
  75. #include <libc.h>
  76. #undef atof
  77. #else
  78. #if defined(atarist) || defined(VMS)
  79. #include <unixlib.h>
  80. #else
  81. #include <unistd.h>
  82. #endif    /* atarist || VMS */
  83. #endif    /* Next */
  84. #else    /* STDC_HEADERS */
  85. #include "protos.h"
  86. #endif    /* STDC_HEADERS */
  87.  
  88. #if defined(ultrix) && !defined(Ultrix41)
  89. extern char * getenv P((char *name));
  90. extern double atof P((char *s));
  91. #endif
  92.  
  93. #ifdef sparc
  94. /* nasty nasty SunOS-ism */
  95. #include <alloca.h>
  96. #ifdef lint
  97. extern char *alloca();
  98. #endif
  99. #else /* not sparc */
  100. #if (!defined(atarist)) && (!defined(NeXT)) && (!defined(alloca))
  101. extern char *alloca();
  102. #endif /* atarist */
  103. #endif /* sparc */
  104.  
  105. #ifdef HAVE_UNDERSCORE_SETJMP
  106. /* nasty nasty berkelixm */
  107. #define setjmp    _setjmp
  108. #define longjmp    _longjmp
  109. #endif
  110.  
  111. /*
  112.  * if you don't have vprintf, but you are BSD, the version defined in
  113.  * vprintf.c should do the trick.  Otherwise, try this and cross your fingers.
  114.  */
  115. #if defined(VPRINTF_MISSING) && !defined(DOPRNT_MISSING) && !defined(BSDSTDIO)
  116. #define vfprintf(fp,fmt,arg)    _doprnt((fmt), (arg), (fp))
  117. #endif
  118.  
  119. #ifdef VMS
  120. /* some macros to redirect to code in vms/vms_misc.c */
  121. #define exit        vms_exit
  122. #define strerror    vms_strerror
  123. #define strdup        vms_strdup
  124. extern void  exit P((int));
  125. extern char *strerror P((int));
  126. extern char *strdup P((const char *str));
  127. # ifndef NO_TTY_FWRITE
  128. #define fwrite        tty_fwrite
  129. #define fclose        tty_fclose
  130. extern size_t fwrite P((const void *,size_t,size_t,FILE *));
  131. extern int    fclose P((FILE *));
  132. # endif
  133. extern void vms_arg_fixup P((int *,char ***));
  134. #endif  /*VMS*/
  135.  
  136. #ifndef _MSC_VER
  137. extern int errno;    /* not necessary on many systems, but it can't hurt */
  138. #endif
  139.  
  140. #define    GNU_REGEX
  141. #ifdef GNU_REGEX
  142. #include "regex.h"
  143. #include "dfa.h"
  144. typedef struct Regexp {
  145.     struct re_pattern_buffer pat;
  146.     struct re_registers regs;
  147.     struct regexp dfareg;
  148.     int dfa;
  149. } Regexp;
  150. #define    RESTART(rp,s)    (rp)->regs.start[0]
  151. #define    REEND(rp,s)    (rp)->regs.end[0]
  152. #else    /* GNU_REGEX */
  153. #endif    /* GNU_REGEX */
  154.  
  155. #ifdef atarist
  156. #define read _text_read /* we do not want all these CR's to mess our input */
  157. extern int _text_read (int, char *, int);
  158. #endif
  159.  
  160. #ifndef DEFPATH
  161. #define DEFPATH    ".:/usr/local/lib/awk:/usr/lib/awk"
  162. #endif
  163.  
  164. #ifndef ENVSEP
  165. #define ENVSEP    ':'
  166. #endif
  167.  
  168. /* ------------------ Constants, Structures, Typedefs  ------------------ */
  169. #define AWKNUM    double
  170.  
  171. typedef enum {
  172.     /* illegal entry == 0 */
  173.     Node_illegal,
  174.  
  175.     /* binary operators  lnode and rnode are the expressions to work on */
  176.     Node_times,
  177.     Node_quotient,
  178.     Node_mod,
  179.     Node_plus,
  180.     Node_minus,
  181.     Node_cond_pair,        /* conditional pair (see Node_line_range) */
  182.     Node_subscript,
  183.     Node_concat,
  184.     Node_exp,
  185.  
  186.     /* unary operators   subnode is the expression to work on */
  187. /*10*/    Node_preincrement,
  188.     Node_predecrement,
  189.     Node_postincrement,
  190.     Node_postdecrement,
  191.     Node_unary_minus,
  192.     Node_field_spec,
  193.  
  194.     /* assignments   lnode is the var to assign to, rnode is the exp */
  195.     Node_assign,
  196.     Node_assign_times,
  197.     Node_assign_quotient,
  198.     Node_assign_mod,
  199. /*20*/    Node_assign_plus,
  200.     Node_assign_minus,
  201.     Node_assign_exp,
  202.  
  203.     /* boolean binaries   lnode and rnode are expressions */
  204.     Node_and,
  205.     Node_or,
  206.  
  207.     /* binary relationals   compares lnode and rnode */
  208.     Node_equal,
  209.     Node_notequal,
  210.     Node_less,
  211.     Node_greater,
  212.     Node_leq,
  213. /*30*/    Node_geq,
  214.     Node_match,
  215.     Node_nomatch,
  216.  
  217.     /* unary relationals   works on subnode */
  218.     Node_not,
  219.  
  220.     /* program structures */
  221.     Node_rule_list,        /* lnode is a rule, rnode is rest of list */
  222.     Node_rule_node,        /* lnode is pattern, rnode is statement */
  223.     Node_statement_list,    /* lnode is statement, rnode is more list */
  224.     Node_if_branches,    /* lnode is to run on true, rnode on false */
  225.     Node_expression_list,    /* lnode is an exp, rnode is more list */
  226.     Node_param_list,    /* lnode is a variable, rnode is more list */
  227.  
  228.     /* keywords */
  229. /*40*/    Node_K_if,        /* lnode is conditonal, rnode is if_branches */
  230.     Node_K_while,        /* lnode is condtional, rnode is stuff to run */
  231.     Node_K_for,        /* lnode is for_struct, rnode is stuff to run */
  232.     Node_K_arrayfor,    /* lnode is for_struct, rnode is stuff to run */
  233.     Node_K_break,        /* no subs */
  234.     Node_K_continue,    /* no stuff */
  235.     Node_K_print,        /* lnode is exp_list, rnode is redirect */
  236.     Node_K_printf,        /* lnode is exp_list, rnode is redirect */
  237.     Node_K_next,        /* no subs */
  238.     Node_K_exit,        /* subnode is return value, or NULL */
  239. /*50*/    Node_K_do,        /* lnode is conditional, rnode stuff to run */
  240.     Node_K_return,
  241.     Node_K_delete,
  242.     Node_K_getline,
  243.     Node_K_function,    /* lnode is statement list, rnode is params */
  244.  
  245.     /* I/O redirection for print statements */
  246.     Node_redirect_output,    /* subnode is where to redirect */
  247.     Node_redirect_append,    /* subnode is where to redirect */
  248.     Node_redirect_pipe,    /* subnode is where to redirect */
  249.     Node_redirect_pipein,    /* subnode is where to redirect */
  250.     Node_redirect_input,    /* subnode is where to redirect */
  251.  
  252.     /* Variables */
  253. /*60*/    Node_var,        /* rnode is value, lnode is array stuff */
  254.     Node_var_array,        /* array is ptr to elements, asize num of
  255.                  * eles */
  256.     Node_val,        /* node is a value - type in flags */
  257.  
  258.     /* Builtins   subnode is explist to work on, proc is func to call */
  259.     Node_builtin,
  260.  
  261.     /*
  262.      * pattern: conditional ',' conditional ;  lnode of Node_line_range
  263.      * is the two conditionals (Node_cond_pair), other word (rnode place)
  264.      * is a flag indicating whether or not this range has been entered.
  265.      */
  266.     Node_line_range,
  267.  
  268.     /*
  269.      * boolean test of membership in array lnode is string-valued
  270.      * expression rnode is array name 
  271.      */
  272.     Node_in_array,
  273.  
  274.     Node_func,        /* lnode is param. list, rnode is body */
  275.     Node_func_call,        /* lnode is name, rnode is argument list */
  276.  
  277.     Node_cond_exp,        /* lnode is conditonal, rnode is if_branches */
  278.     Node_regex,
  279. /*70*/    Node_hashnode,
  280.     Node_ahash,
  281.     Node_NF,
  282.     Node_NR,
  283.     Node_FNR,
  284.     Node_FS,
  285.     Node_RS,
  286.     Node_FIELDWIDTHS,
  287.     Node_IGNORECASE,
  288.     Node_OFS,
  289.     Node_ORS,
  290.     Node_OFMT,
  291.     Node_CONVFMT
  292. } NODETYPE;
  293.  
  294. /*
  295.  * NOTE - this struct is a rather kludgey -- it is packed to minimize
  296.  * space usage, at the expense of cleanliness.  Alter at own risk.
  297.  */
  298. typedef struct exp_node {
  299.     union {
  300.         struct {
  301.             union {
  302.                 struct exp_node *lptr;
  303.                 char *param_name;
  304.             } l;
  305.             union {
  306.                 struct exp_node *rptr;
  307.                 struct exp_node *(*pptr) ();
  308.                 Regexp *preg;
  309.                 struct for_loop_header *hd;
  310.                 struct exp_node **av;
  311.                 int r_ent;    /* range entered */
  312.             } r;
  313.             union {
  314.                 char *name;
  315.                 struct exp_node *extra;
  316.             } x;
  317.             short number;
  318.             unsigned char reflags;
  319. #            define    CASE    1
  320. #            define    CONST    2
  321. #            define